package main

import "fmt"

func longestPalindrome(s string) string {
	if len(s) == 1 || s == "" || s == reverse(s) {
		return s
	}
	res := ""
	Mx := 0
	My := 0
	count := 0
	for i := 0; i < len(s); i++ {
		res = string(s[i])
		for k := i + 1; k < len(s); k++ {
			if string(s[k]) == string(res[0]) {
				res = s[i : k+1]
				if res == reverse(res) && count < len(res) {
					count = len(res)
					Mx = i
					My = k
				}
			}
		}
	}
	res = s[Mx : My+1]
	return res
}
func reverse(str string) string {
	// write code here
	r := []rune(str)
	i := 0
	for j := len(str) - 1; i <= j; {
		r[i], r[j] = r[j], r[i]
		i++
		j--
	}
	return string(r)
}

//func longestPalindrome(s string) string {
//	if s == "" {
//		return ""
//	}
//	start, end := 0, 0
//	for i := 0; i < len(s); i++ {
//		left1, right1 := expandAroundCenter(s, i, i)
//		left2, right2 := expandAroundCenter(s, i, i + 1)
//		if right1 - left1 > end - start {
//			start, end = left1, right1
//		}
//		if right2 - left2 > end - start {
//			start, end = left2, right2
//		}
//	}
//	return s[start:end+1]
//}
//
//func expandAroundCenter(s string, left, right int) (int, int) {
//	for ; left >= 0 && right < len(s) && s[left] == s[right]; left, right = left-1 , right+1 { }
//	return left + 1, right - 1
//}
func main() {
	fmt.Println(longestPalindrome("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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